home *** CD-ROM | disk | FTP | other *** search
- #include "QD3DtoQTVR.h"
- #include "extern.h"
- #include "document.h"
- #include "context.h"
- #include "camera.h"
- #include "lights.h"
-
- DocumentPtr MyNewDocument()
- {
- DocumentPtr theDocument;
- CWindowPtr theWindow;
- Rect theRect = { 0, 0, 16, 16 };
- TQ3Param2D uvValues = {-1.0, -1.0};
- TQ3DrawContextObject theDrawContext ;
- TQ3AttributeSet viewSet;
- Rect myBounds = kMyBoundsRect;
- TQ3ColorRGB clearColor = kMyClearColor;
- TQ3CameraObject camera = NULL ;
- RGBColor blackColor = kMyBlackColor;
-
- // create the document record
- theDocument = (DocumentPtr )NewPtrClear(sizeof(DocumentRecord));
-
- // create the window to display the rendering and add referneces to the document
- theWindow = (CWindowPtr)NewCWindow(0L,&myBounds,"\pRendering Window",true,documentProc,(WindowPtr)-1L,true,NULL);
- if (theWindow == nil)
- goto bail;
- theDocument->theWindow = theWindow;
- SetWRefCon((WindowPtr)theWindow, (long)theDocument ) ;
-
- // create and setup the offscreen buffer
- // ** Notice that QuickDraw 3D prefers direct color
- NewGWorld(&theDocument->drawContextOffscreen, 32, &theWindow->portRect, nil, nil, 0L );
- if (theDocument->drawContextOffscreen == NULL)
- goto bail;
-
- SetGWorld(theDocument->drawContextOffscreen,nil);
- RGBBackColor(&blackColor);
- RGBForeColor(&blackColor);
- EraseRect(&theDocument->drawContextOffscreen->portRect);
-
- // zero out the file spec
- theDocument->theFileSpec.vRefNum = 0 ;
- theDocument->theFileSpec.parID = 0 ;
- theDocument->theFileSpec.name[0] = '\0' ;
-
- // Create the new PixMap draw context
- theDrawContext = MyNewDrawContext( theDocument ) ;
- if (theDrawContext == NULL)
- goto bail;
-
- // Create the view and setup the view attributes
- theDocument->theView = Q3View_New();
- Q3View_GetDefaultAttributeSet(theDocument->theView, &viewSet);
- Q3AttributeSet_Add(viewSet,
- kQ3AttributeTypeSpecularColor, &clearColor);
- Q3AttributeSet_Add(viewSet,
- kQ3AttributeTypeSurfaceUV, &clearColor);
- Q3AttributeSet_Add(viewSet,
- kQ3AttributeTypeShadingUV, &clearColor);
- Q3Object_Dispose(viewSet);
- Q3View_SetDrawContext(theDocument->theView, theDrawContext);
- Q3Object_Dispose(theDrawContext);
-
- // Initialize the model rotation used for model rotation
- Q3Matrix4x4_SetIdentity(&theDocument->modelRotation);
-
- // Add more model and view properties to the document record
- theDocument->documentGroup = nil;
- theDocument->documentGroupScale = 1.0;
- theDocument->currentInterpolation = kQ3InterpolationStylePixel;
- theDocument->illuminationShader = Q3PhongIllumination_New();
-
- // Create the camera and add it to the view
- camera = MyNewCamera( theDocument->theWindow ) ;
- Q3View_SetCamera(theDocument->theView, camera );
- Q3Object_Dispose(camera);
-
- // Add the renderer to the view
- Q3View_SetRendererByType(theDocument->theView, kQ3RendererTypeInteractive);
-
- // Setup the window gworld
- SetGWorld(theWindow,nil);
-
- return(theDocument);
-
- bail:
- if (theDocument->drawContextOffscreen)
- DisposeGWorld(theDocument->drawContextOffscreen);
-
- if (theWindow)
- DisposeWindow((WindowPtr) theWindow);
-
- if (theDocument)
- DisposePtr((Ptr)theDocument);
-
- return( (DocumentPtr )nil );
- }
-
-
- void MyCloseDocument( DocumentPtr theDocument )
- {
- // if we are here we can assume the document has been saved (if required) and
- // that we can junk all of the data structures associated with the document
-
- // if it has a file associated, close it
- if (theDocument->fRefNum)
- FSClose(theDocument->fRefNum);
-
- // and we can dispose of the window
- if(theDocument->theWindow)
- DisposeWindow((WindowPtr)theDocument->theWindow);
-
- // dispose of our QuickDraw 3d view object
- if(theDocument->theView)
- Q3Object_Dispose(theDocument->theView);
-
- // if we have a group associated with the document, then delete that
- if(theDocument->documentGroup)
- Q3Object_Dispose(theDocument->documentGroup);
-
- if(theDocument->illuminationShader)
- Q3Object_Dispose(theDocument->illuminationShader);
-
- if(theDocument->drawContextOffscreen != nil )
- DisposeGWorld(theDocument->drawContextOffscreen) ;
-
- // finally dispose of the storage used for the document and
- // decrement the document count
- if( theDocument != nil )
- DisposPtr((Ptr) theDocument);
- }
-
-